package com.hisense.ovcloud.mqtt.router.config;

import com.hisense.ovcloud.commons.dto.common.AesInfoInCache;
import com.hisense.ovcloud.commons.dto.common.ProductInfoInCache;
import com.hisense.ovcloud.commons.tools.LocalTimedCacheUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class LocalCacheConfig {
    private final RouterConfig routerConfig;

    public LocalCacheConfig(RouterConfig routerConfig) {
        this.routerConfig = routerConfig;
    }

    @Bean
    @Qualifier("productInfoInCache")
    public LocalTimedCacheUtil<ProductInfoInCache> productInfoInCache(){
        return new LocalTimedCacheUtil<>(routerConfig.getCacheDefaultTimeoutSeconds(), routerConfig.getSchedulePruneSecond());
    }

    @Bean
    @Qualifier("aesInfoInCache")
    public LocalTimedCacheUtil<AesInfoInCache> aesInfoInCache(){
        return new LocalTimedCacheUtil<>(routerConfig.getCacheDefaultTimeoutSeconds(), routerConfig.getSchedulePruneSecond());
    }
}
